import json

import requests

from utils.api_util import api
from utils.response_util import process_response


# 测试获取验证码接口
def post_code(data):
    """
    获取短信验证码
    :param data:
    :return:
    """
    f = api.post_s("/code/", data=data)
    return process_response(f)


# 注册用户
def register(code, mobile, password):
    """
    注册用户
    :param code:
    :param mobile:
    :param password:
    :return:
    """
    data = {
        "code": code,
        "password": password,
        "username": mobile,
    }

    f = api.post_s("/users/", data=data)
    return process_response(f)


# 测试登录接口
def login_user(data):
    """
    用户登录接口
    :param data:
    :return:
    """
    f = api.post_s("/login/", data=data)
    return process_response(f)


# 测试加入购物车
def add_shopping_cart(param, headers):
    """
    添加食物到购物车
    :param headers:
    :param param:
    :return:
    """
    # headers = {
    #     "Authorization": "JWT " + token
    # }

    f = api.post_s('/shopcarts/', data=param, headers=headers)
    return process_response(f)


# 测试添加留言
def add_message(data, files, headers):
    """
    添加留言
    :param files:
    :param data:
    :param headers:
    :return:
    """
    # headers = {
    #     "Authorization": "JWT " + token
    # }
    f = api.post_s('/messages/', data=data, files=files, headers=headers)
    return process_response(f)
